<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<c:if test="${contrat==null}">
    <div class="error message">
        <h3>Message</h3>
        <p>Contrat inexistant</p>
    </div>


</c:if>
<fieldset class="form-container " style="width:80%;margin-left:5%;"> 
    <legend class="form-title"><h2>Contrat entre ${contrat.adherent.nomPrenom} et ${contrat.employe.nom}&nbsp;${contrat.employe.prenom}</h2></legend>
    <fieldset style="float: left;position: relative;margin-left:4%;">
        <legend class="form-title">L'adh&eacute;rent</legend>
        <table >
            <tbody>
                <tr><td style="width : 35%">Nom Pr&eacute;nom :</td><td>${contrat.adherent.nomPrenom}</td></tr>

                <tr class="alt"><td>Adresse :</td><td>${contrat.adherent.adresse}<br/>
                        ${contrat.adherent.complementAdresse}<br/>
                        ${contrat.adherent.codePostal}- ${contrat.adherent.ville}</td></tr>
                <tr class="alt"><td>T&eacute;l&eacute;phone :</td>
                    <td>${contrat.adherent.telephone}</td></tr>
                <tr><td>Mobile :</td>
                    <td>${contrat.adherent.mobile}</td></tr>

                <tr  class="alt"><td>Num&eacute;ro Urssaf :</td><td>${contrat.adherent.numUrssaf}</td></tr>
                <tr ><td>Num&eacutero Siret :</td><td>${contrat.adherent.numSiret}</td></tr>
            </tbody>
        </table>
    </fieldset>
    <fieldset style="float: left;position: relative;margin-left: 10%;">
        <legend class="form-title">L'employ&eacute;</legend>
        <table>
            <tbody>
                <tr><td style="width : 40%">Nom Pr&eacute;nom :</td><td>${contrat.employe.nom}&nbsp;${contrat.employe.prenom}</td></tr>
                <tr class="alt"><td >Nom jeune fille :</td><td>${contrat.employe.nomJeuneFille}</td></tr>

                <tr><td>Adresse :</td><td>${contrat.employe.adresse}<br/>
                        ${contrat.employe.complementAdresse}<br/>
                        ${contrat.employe.codePostal}- ${contrat.employe.ville}</td></tr>
                <tr class="alt"><td>Num&eacute;ro de t&eacute;l&eacute;phone :</td>
                    <td>${contrat.employe.telephone}</td></tr>
                <tr ><td>Mobile :</td>
                    <td>${contrat.employe.mobile}</td></tr>

                <tr class="alt"><td>Num&eacute;ro S&eacute;curit&eacute; social:</td><td>${contrat.employe.numSecu}</td></tr>

            </tbody>
        </table>
    </fieldset>
    <fieldset style="clear: left;">
        <legend class="form-title">Le contrat</legend>

        <table>
            <tbody>
                <tr><td style="width : 40%">Le modèle de bulletin de paie :</td><td><c:if test="${contrat.modelPaie.nom==null}">Aucun</c:if>${contrat.modelPaie.nom}</td></tr>
                <tr class="alt"><td >La date d'entr&eacute;e :</td><td><fmt:formatDate pattern="dd MM yyyy" value="${contrat.dateEntree}" /></td></tr>

                <tr><td>Le taux horaire de base :</td><td>${contrat.salaireBase}</td></tr>
                <tr><td>Etat du contrat :</td><td>${contrat.etatContrat}</td></tr>

            </tbody>
        </table>
    </fieldset>
    <fieldset style="clear: left;">
        <legend class="form-title">Les bulletins de paies</legend>
       
            <table  class="tablesorter">
                <thead>
                    <tr><th>Periode</th><th>Etat</th><th>Lien</th><th>Actions</th></tr>

                </thead>
                <tbody>
                    <c:forEach var="bulletin" items="${contrat.bulletinPaie}">
                        <tr>
                            <td> <fmt:formatDate pattern="MM yyyy"  value="${bulletin.periode}"  /> 
                            </td>
                            <td>${bulletin.etatBulletin}</td>
                            <td> <a href="/download/Bulletin/get.do?id=${bulletin.id}">T&eacute;l&eacute;charger</a></td>
                            <td> <a href="/bulletin/show.do?id=${bulletin.id}" >Consulter</a><br/>
                                <c:if test="${bulletin.etatBulletin!='declare' &&  bulletin.etatBulletin!='archive'}"> <a id="updateBulletin${bulletin.id}" href="/bulletin/update.do?id=${bulletin.id}" >Modifier</a><br/>

                                    <a id="delBulletin" href="/bulletin/delete.do?id=${bulletin.id}">Supprimer</a><br/>
                                </c:if>
                               
                                <c:if test="${bulletin.etatBulletin=='imprime'}"> 
                                    <script>
                                        $(function() {
                                            $("#dialog${bulletin.id}").dialog({
                                                autoOpen: false,
                                                modal: true,
                                                buttons: {
                                                    "Confirmer": function() {

                                                        $(this).dialog("close");
                                                        window.location = "/bulletin/update.do?id=${bulletin.id}";
                                                    },
                                                    "Annuler": function() {
                                                        $(this).dialog("close");
                                                    }
                                                }
                                            });

                                            $("#updateBulletin${bulletin.id}").click(function(e) {
                                                e.preventDefault();
                                                $("#dialog${bulletin.id}").dialog("open");
                                            });
                                        });
                                    </script>

                                    <div id="dialog${bulletin.id}" title="Confirmer la modification">
                                        <p><span class="ui-icon ui-icon-alert" style="float:left; margin:0 7px 20px 0;"></span>Le bulletin a &eacute;t&eacute; d&eacute;j&agrave; t&eacute;l&eacute;charg&eacute;.<br/>
                                            Voulez vous le modifier ?
                                        </p>
                                    </div>

                                </c:if>
                            </td>
                        </tr>
                    </c:forEach> 
                </tbody>
            </table>
    </fieldset>
    <div class="submit-container">
        <a href="/contrat/update.do?id=${contrat.id}" class="submit-button">Modifider</a>
        <a href="/bulletin/add.do?idContrat=${contrat.id}" class="submit-button">Saisir un bulletin de paie</a>
        <a href= "/contrat/index.do" class="submit-button">Annuler</a>
    </div>
</fieldset>

<script>
    $(function() {


        $("table").tablesorter({widgets: ['zebra']}).tablesorterPager({container: $("#pager")});

    });
</script>